﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace SmartMD.Manager.Specimens
{
    /// <summary>
    /// Interaction logic for SpecStoreWindow.xaml
    /// </summary>
    public partial class SpecManagerWindow : BaseWindow
    {
        private UIElement _querySpecPanel;
        private UIElement _storeSpecPanel;
        private UIElement _locateSpecPanel;
        private string _currentPanelName;

        public SpecManagerWindow()
        {
            InitializeComponent();
            this.Title = "标本入库";
            Load("标本查询");
        }
        public static string ModuleName
        {
            get { return "标本数据"; }
        }

        private void btnOpenView_Click(object sender, RoutedEventArgs e)
        {
            var button = (ToggleButton)sender;
            Load(button.Tag);
        }
        protected override void OnWindowActivated()
        {
            switch(_currentPanelName)
            {
                case "标本查询":
                    (_querySpecPanel as QuerySpecPanel).OnWindowActivated();
                    break;
                case "标本入库":
                    (_storeSpecPanel as StoreSpecPanel).OnWindowActivated();
                    break;
                case "标本定位":
                    (_locateSpecPanel as LocateSpecPanel).OnWindowActivated();
                    break;
                default:
                    break;
            }        
        }
        public override void Load(object param)
        {
            if (param == null) return;

            foreach (ToggleButton btn in panelButtons.Children)
            {
                btn.IsChecked = btn.Tag.Equals(param);
            }
            
            var sParam = param.ToString();
            _currentPanelName = sParam;
            this.Title = "标本数据 - " + sParam;
            this.gridContent.Children.Clear();
            switch (sParam)
            {
                case "标本查询":
                    this.gridContent.Children.Add(GetQuerySpecPanel());
                    break;
                case "标本入库":
                    this.gridContent.Children.Add(GetStoreSpecPanel());
                    break;
               
                case "标本定位":
                    LocateSpecPanel panel = (LocateSpecPanel)GetLocateSpecPanel();
                    this.gridContent.Children.Add(panel);
                    panel.lbContainer.Height = 500;
                    panel.CM.Height = 0;
                    break;
            }
        }
        public UIElement GetQuerySpecPanel()
        {
            return _querySpecPanel ?? (_querySpecPanel = new QuerySpecPanel());
        }
        public UIElement GetStoreSpecPanel()
        {
            return _storeSpecPanel ?? (_storeSpecPanel = new StoreSpecPanel());
        }
       
        public UIElement GetLocateSpecPanel()
        {
            _locateSpecPanel = null;
            return _locateSpecPanel ?? (_locateSpecPanel = new LocateSpecPanel());
        }
    }
}
